package com.lineage.server.model.Instance;

import com.lineage.server.model.L1AttackPc;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_NPCPack_Ill;
import com.lineage.server.serverpackets.S_SkillBrave;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Npc;
import com.lineage.server.types.Point;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1IllusoryInstance extends L1NpcInstance {
  private static final long serialVersionUID = 1L;
  
  private static final Log _log = LogFactory.getLog(L1IllusoryInstance.class);
  
  public L1IllusoryInstance(L1Npc template) {
    super(template);
  }
  
  public void onPerceive(L1PcInstance perceivedFrom) {
    try {
      if (perceivedFrom.get_showId() != get_showId())
        return; 
      perceivedFrom.addKnownObject((L1Object)this);
      if (getCurrentHp() > 0) {
        perceivedFrom.sendPackets((ServerBasePacket)new S_NPCPack_Ill(this));
        onNpcAI();
        if (getBraveSpeed() > 0)
          perceivedFrom.sendPackets((ServerBasePacket)new S_SkillBrave(getId(), getBraveSpeed(), 600000)); 
      } else {
        perceivedFrom.sendPackets((ServerBasePacket)new S_NPCPack_Ill(this));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void setLink(L1Character cha) {
    if (get_showId() != cha.get_showId())
      return; 
    if (cha instanceof L1PcInstance && cha.getMap().isSafetyZone((Point)cha.getLocation()))
      return; 
    if (cha != null && this._hateList.isEmpty()) {
      this._hateList.add(cha, 0);
      checkTarget();
    } 
  }
  
  public void onNpcAI() {
    if (isAiRunning())
      return; 
    setActived(false);
    startAI();
  }
  
  public void onTalkAction(L1PcInstance pc) {}
  
  public void onAction(L1PcInstance pc) {
    try {
      L1AttackPc l1AttackPc = new L1AttackPc(pc, this);
      l1AttackPc.action();
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void ReceiveManaDamage(L1Character attacker, int mpDamage) {}
  
  public void receiveDamage(L1Character attacker, int damage) {}
  
  public void setCurrentHp(int i) {}
  
  public void setCurrentMp(int i) {}
}
